/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.task.api  
 */
package com.apache.audit.util;

import com.apache.method.SystemRunnable;
import com.apache.method.ThreadPool;

/**
 * description:  日志线程池启动控制类
 * @author Hou Dayu 创建时间：2015-1-14  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class ScheduledExecutor {

	private static ScheduledExecutor instance;
	private int poolNum = 3;
	private ThreadPool taskPool;

	//private ThreadPoolTaskExecutor taskPool;

	private ScheduledExecutor() {
	}

	/**
	 * description:  创建单实例方法
	 * @return   
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public static ScheduledExecutor newInstance() {
		if (null == instance) {
			instance = new ScheduledExecutor();
			instance.init();
		}
		return instance;
	}

	/**
	 * description: 初始化方法
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public void init() {
		instance = this;
		taskPool = new ThreadPool(poolNum, "Logger执行线程池");
	}

	public void saveLogger(SystemRunnable runnable) {
		if (null != runnable) {
			taskPool.execute(runnable);
		}
	}

	/**
	 * description:  销毁方法
	 * @author Hou Dayu  
	 * @update 2015-1-14
	 */
	public void destroy() {
		taskPool.closePool();
		taskPool = null;
		instance = null;
	}

	public void setPoolNum(int poolNum) {
		this.poolNum = poolNum;
	}

}
